package com.itheima.mapper;

import com.itheima.pojo.Brand;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BrandMapper {

    //查询方法
    @Select("select * from tb_brand;")
    @ResultMap("brandResultMap")
    List<Brand> selectAll();

    //新增方法
    @Insert("insert into tb_brand values (null,#{brandName},#{companyName},#{ordered},#{description},#{status})")
    void add(Brand brand);

    //根据id删除方法
    @Delete("delete from tb_brand where id = #{id}")
    void deleteById(Integer id);

    //修改方法
    @Update("update tb_brand set" +
            " brand_name = #{brandName},company_name = #{companyName},ordered = #{ordered},description = #{description},status = #{status} " +
            "where id = #{id}")
    void updateById(Brand brand);


    void deleteByIds(@Param("ids") int[] ids);

    @Select("select * from tb_brand limit #{begin},#{pageSize}")
    @ResultMap("brandResultMap")
    List<Brand> rows(@Param("begin") int begin,@Param("pageSize") int pageSize);

    @Select("select COUNT(*) from tb_brand")
    int selectCount();

    /**
     * 分页条件查询
     * @param begin
     * @param size
     * @return
     */
    List<Brand> selectByPageAndCondition(@Param("begin") int begin,@Param("size") int size,@Param("brand") Brand brand);

    /**
     * 根据条件查询总记录数
     * @return
     */
    int selectTotalCountByCondition(Brand brand);
}
